package com.thientan.service

import com.thientan.export.ExportRequest
import com.thientan.model.HopDong
import com.thientan.model.KhachHang

class HopDongService extends AbstractService {
	@Override
	protected Long[] getColWidth() {
		return [30 , 50 , 50, 70, 45 , 40, 70] as Long[]
	}

	@Override
	protected String[] getColTitles() {
		return ['STT', 'Ngày trả', 'Tiền thu', 'Tiền còn nợ', 'KH ký', 'TN ký', 'Tên thu ngân'] as String[]
	}

	@Override
	protected String[] getColNames() {
		return ['stt', 'ngaytra', 'tienthu', 'tienconno', 'khky', 'tnky', 'tenthungan'] as String[]
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected Class<?>[] getExportColType() {
		return [
			Integer.class,
			String.class,
			String.class,
			String.class,
			String.class,
			String.class,
			String.class
		]as Class<?>[]
	}

	@Override
	void prepareParametersBeforeExport(ExportRequest er){
		er.addParameter("ngayin", this.exportData?.ngayin)
		er.addParameter("tenkhachhang", this.exportData?.tenkhachhang)
		er.addParameter("diachi", this.exportData?.diachi)
		er.addParameter("dienthoai", this.exportData?.dienthoai)
		er.addParameter("tongtien", this.exportData?.tongtien)
		er.addParameter("doitruong", this.exportData?.doitruong)
		er.addParameter("nv1", this.exportData?.nv1)
		er.addParameter("nv2", this.exportData?.nv2)
		er.addParameter("tratruoc", this.exportData?.tratruoc)
		er.addParameter("conlai", this.exportData?.conlai)
		er.addParameter("mahopdong", this.exportData?.mahopdong)
		er.addParameter("mavachpath", this.exportData?.mavachpath)
		er.addParameter("logopath", this.exportData?.logopath)
	}
	
	/**
	 * Modify HopDong: save KhachHang info then save HopDong info.
	 * @param hd
	 * @param kh
	 * @return
	 */
	HopDong edit(HopDong hd, KhachHang kh) {
		kh.save()
		hd.save()
	}
}
